﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _67父子类型转换
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Animal a1 = new Dog();//隐式转换

            Dog d1 = (Dog)a1;//强转
            Dog d2 = a1 as Dog;//as转

            //Cat c1 = (Cat)a1;//强转失败会抛出异常
            Cat c2 = a1 as Cat;//失败会返回null

            Console.WriteLine(a1 is Dog);//true
            Console.WriteLine(a1 is Cat);//false
        }
    }

    internal class Animal
    {
    }
    internal class Dog : Animal
    {
    }
    internal class Cat : Animal
    {
    }
}